/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package view;

import controller.ControlManager;
import java.awt.Color;
import java.awt.Graphics;
import model.Cell;
import model.Map;
import model.Object;
/**
 *
 * @author Nevermade
 */
public class MiniMap extends javax.swing.JPanel {

    /**
     * Creates new form MiniMap
     */
    
    private int sqH;
    private int sqW;
    private int panelW=200;
    private int panelH=200;
    private ControlManager cM=MainWindow.man;
    private Map map;
    public void prepareMiniMap(){
        map=cM.getMap();
        sqW=panelW/map.getColumn();
        sqH=panelH/map.getRow();
        
        
    }
    public void refreshMiniMap(Graphics g){
        int x=map.getColumn();
        int y=map.getRow();
        
        for(int j=0;j<y;j++){
            for(int i=0;i<x;i++){
                Cell c=map.getCell(i, j);
                Color color=getColor(c);
                g.setColor(color);
                g.fillRect(i*sqW,j*sqH, sqW, sqH);
            }
        }
    }
    public Color getColor(Cell c){
        Color color=null;
        Object obj=c.getObject();
        if(obj!=null){
            color=Color.RED;
        }else{
            int type=c.getType();
            switch(type){
                case 0: color=Color.GREEN;break;
                case 1: color=Color.ORANGE;break;    
            }               
            
        }
        return color;
    }
    @Override
    public void paintComponent(Graphics g){
        super.paintComponent(g);
        refreshMiniMap(g);
    }
    
    public MiniMap() {
        prepareMiniMap();
        initComponents();
    }

    /**
     * This method is called from within the constructor to initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is always
     * regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        setPreferredSize(new java.awt.Dimension(500, 500));

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(this);
        this.setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGap(0, 169, Short.MAX_VALUE)
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGap(0, 159, Short.MAX_VALUE)
        );
    }// </editor-fold>//GEN-END:initComponents
    // Variables declaration - do not modify//GEN-BEGIN:variables
    // End of variables declaration//GEN-END:variables
}
